import Foundation
import LunarSwift

public class DayModel: NSObject, Identifiable {
    public var id = UUID()
    public var events: [CSEvent] = []
    public var reminders: [CSReminder] = []
    public var festivals: [String] = []
    public var lunar: String = ""
    public var date: Date!
    public var mode: Mode = .current
    public var tiaoxiu: TiaoXiu = .none
    // 宜
    public var suitable: [String] = []
    // 忌
    public var taboo: [String] = []
    // 二十八宿
    public var xiu: String = ""
    // 星宿吉凶
    public var xiuLuck: String = ""
    // 星座
    public var constellation: String = ""

    // 是否为显示的节日
    public var isFestival: Bool {
        festivals.contains(where: { $0.contains(lunar) })
    }

    // 太阳历
    private var solar: Solar

    public init(id: UUID = UUID(), events: [CSEvent] = [], reminders: [CSReminder] = [], festivals: [String] = [], lunar: String = "", date: Date, mode: Mode = .current, tiaoxiu: TiaoXiu = .none) {
        self.id = id
        self.events = events
        self.reminders = reminders
        self.festivals = festivals
        self.lunar = lunar
        self.date = date
        self.mode = mode
        self.tiaoxiu = tiaoxiu
        self.solar = Solar(date: date)
        let nlunar = solar.lunar
        self.suitable = LunarUtil.getDayYi(monthGanZhi: nlunar.monthInGanZhi, dayGanZhi: nlunar.dayInGanZhi)
        self.taboo = LunarUtil.getDayJi(monthGanZhi: nlunar.monthInGanZhi, dayGanZhi: nlunar.dayInGanZhi)
        self.xiu = nlunar.xiu
        self.xiuLuck = nlunar.xiuLuck
        self.constellation = solar.xingZuo
    }
    
    public enum Mode: Int {
        case last, current, next
    }
    
    public enum TiaoXiu: Int {
        case none = 0
        case work = 1
        case rest = 2
    }
}
